﻿package mortal.game.view.copy.worldBoss.WorldBossAllot
{
    import Message.Client.*;
    import com.mui.controls.*;
    import extend.language.*;
    import fl.controls.*;
    import fl.data.*;
    import flash.events.*;
    import mortal.common.global.*;
    import mortal.component.window.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.mvc.core.*;
    import mortal.mvc.interfaces.*;

    public class WorldBossAllotDice extends BaseWindow
    {
        private var _leftTime:SecTimerView;
        private var _getText:GTextFiled;
        private var _getName:GTextFiled;
        private var _tileList:GTileList;
        protected var _data:WorldBossAllotCellData;
        private static var _instance:WorldBossAllotDice;

        public function WorldBossAllotDice(param1:ILayer = null)
        {
            super(param1);
            setSize(353, 495);
            title = Language.getString(21450);
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._leftTime = UIFactory.secTimeView(Language.getString(21451), 105, 60, 180, 22, this, GlobalStyle.textFormatHuang2.setSize(14));
            this._getText = UIFactory.gTextField("", 75, 41, 250, 60, this, GlobalStyle.textFormatLv.setLeading(5).setSize(18).setBold(true));
            this._getText.multiline = true;
            this._getText.wordWrap = true;
            this._getName = UIFactory.gTextField("", 15, 100, 330, 20, this, GlobalStyle.textFormatHuang2.center());
            pushUIToDisposeVec(UIFactory.bg(8, 122, 335, 365, this, ImagesConst.PanelBg));
            pushUIToDisposeVec(UIFactory.bg(8, 122, 335, 24, this, ImagesConst.RegionTitleBg));
            pushUIToDisposeVec(UIFactory.gTextField(Language.getString(21452), 51, 124, 100, 24, this, GlobalStyle.textFormatBai));
            pushUIToDisposeVec(UIFactory.gTextField(Language.getString(21453), 240, 124, 100, 24, this, GlobalStyle.textFormatBai));
            this._tileList = UIFactory.tileList(9, 149, 333, 333, this);
            this._tileList.columnWidth = 333;
            this._tileList.rowHeight = 33;
            this._tileList.horizontalGap = 0;
            this._tileList.verticalGap = 0;
            this._tileList.setStyle("cellRenderer", WorldBossDiceCellRenderer);
            this._tileList.direction = ScrollBarDirection.VERTICAL;
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._leftTime.dispose();
            this._leftTime = null;
            this._tileList.dispose();
            this._tileList = null;
            this._getText.dispose();
            this._getText = null;
            this._getName.dispose();
            this._getName = null;
            this._data.removeEventListener(Event.CHANGE, this.refreshList);
            this._data = null;
            super.disposeImpl(param1);
            return;
        }// end function

        public function updateData(param1:WorldBossAllotCellData) : void
        {
            if (this._data)
            {
                this._data.removeEventListener(Event.CHANGE, this.refreshList);
            }
            this._data = param1;
            this._data.addEventListener(Event.CHANGE, this.refreshList);
            this.refreshList();
            return;
        }// end function

        public function refreshList(param1 = null) : void
        {
            var _loc_2:int = 0;
            this._leftTime.visible = false;
            this._getText.visible = false;
            this._getName.visible = false;
            if (this._data)
            {
                if (this._data.status == EWorldBossAllotStatus._ESignUp)
                {
                    this._leftTime.setParse(Language.getString(21454));
                    _loc_2 = 30 - (ClockManager.instance.nowDate.time - this._data.startDate.time) / 1000;
                    this._leftTime.visible = true;
                    this._leftTime.setLeftTime(_loc_2);
                }
                else if (this._data.status == EWorldBossAllotStatus._EEnd)
                {
                    this._getText.visible = true;
                    if (this._data.getterPlayerName == Cache.instance.role.entityInfo.name)
                    {
                        this._getText.htmlText = Language.getString(21455);
                    }
                    else
                    {
                        this._getText.htmlText = Language.getString(21456);
                        this._getName.visible = true;
                        this._getName.htmlText = Language.getStringByParam(21457, this._data.getterPlayerName, this._data.getterDiceNum);
                    }
                }
                this._tileList.dataProvider = new DataProvider(this._data.diceList);
            }
            return;
        }// end function

        protected function onClickDiceBtn(event:MouseEvent) : void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.WorldBossDice, {bossCode:this._data.bossCode, itemCode:this._data.itemCode}));
            return;
        }// end function

        public static function get instance() : WorldBossAllotDice
        {
            if (!_instance)
            {
                _instance = new WorldBossAllotDice;
            }
            return _instance;
        }// end function

    }
}
